/************************************************************************/
// Copyright (C) 2016, han_gangbiao. All rights reserved.
// Use of this source code is governed by a GPL-v2 license that can be found in the License file.
// 
// [Time]:      2016-1-4 21:53:17
// [Author]:    han_gangbiao [http://my.oschina.net/jackhen]
// [Info]:      
/************************************************************************/

#ifndef INCLUDE_NET_NETINSIDE_NETADDR_H_
#define INCLUDE_NET_NETINSIDE_NETADDR_H_

#include "net/netbasedefine.h"

class netaddr_t
{
public:
	netaddr_t();
	netaddr_t( const char* ip, uint16 port );
	netaddr_t( const struct sockaddr_in& ref_addr );
	netaddr_t( const netaddr_t& ref_other );
	virtual ~netaddr_t();

	netaddr_t& operator= ( const netaddr_t& ref_other );
	bool operator== ( netaddr_t& ref_other ) const;

public:
	virtual bool is_valid() const;
public:
	int set_addr( const char* ip, uint16 port );
	int set_addr( const struct sockaddr_in& ref_addr );
	const struct sockaddr_in* get_addr() const;
	int get_addr_len() const;

	int set_ip( const char* ip );
	int set_port( uint16 port );

	const char* get_ipstr() const;
	unsigned long get_ip() const;
	uint16 get_port() const;

private:
	unsigned long m_ip;
	uint16 m_port;
	union {
		struct sockaddr_in m_addrin;
		//struct sockaddr_in6 m_addrin6;
	} m_inet_addr;
};


#endif //~INCLUDE_NET_NETINSIDE_NETADDR_H_
